<template>
  <div class="wiapper">
    <!--     v-if="swiperList.length" 解决轮播图显示最后一页的问题，当真正的数据过来之后再进行创建 -->
<!--    <swiper ref="mySwiper" :options="swiperOptions" v-if="swiperList.length">-->
    <swiper ref="mySwiper" :options="swiperOptions" v-if="showSwiper">
      <swiper-slide v-for="item in swiperList" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" alt="北京环球度假区"/>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    swiperList: Array
  },
  data () {
    return {
      swiperOptions: {
        // 页码
        pagination: '.swiper-pagination',
        loop: true,
        autoplay: 3000 // 轮播速度
      }
    }
  },
  mounted () {
  },
  computed: {
    // 通过计算属性实现逻辑判断
    showSwiper () {
      return this.swiperList.length
    }
    // swiper () {
    //   return this.$refs.mySwiper.$swiper
    // }
  }
}
</script>

<style scoped lang="stylus">
  .wiapper >>> .swiper-pagination-bullet-active
    background-color #ffffff !important
  .wiapper
    overflow hidden
    width: 100%;
    height: 0;
    padding-bottom 31.25%
    /* padding-bottom取值为百分比的时候，参照的是父元素的宽度,就是进行提前占位，避免资源加载时候的闪烁，还可以让高度自适应  */
    .swiper-img
      width: 100%;
      height: 130px;
</style>
